<?php
declare (strict_types=1);

namespace app\admin\model\advertiser;

use app\BaseModel;
use think\model\relation\HasOne;

/**
 * 广告主充值记录表
 */
class AdvertiserUserRecharge extends BaseModel
{
    /**
     * 定义mode
     * @var array|string[]
     */
    public array $modeArr = [
        1 => '人工充值'
    ];

    /**
     * 获取广告主充值记录列表
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param string $orderby
     * @return array
     */
    public static function getList(array $where, int $page, int $limit, string $orderby = ''): array
    {
        $data = self::where($where)
            ->order($orderby)
            ->with(['advertiserUser' => function ($query) {
                $query->field('id,phone,name');
            }])
            ->paginate(['list_rows' => $limit, 'page' => $page], false)
            ->toArray();
        //遍历数组
        foreach ($data['data'] as &$v) {
            switch ($v['mode']) {
                case 1:
                    $v['mode_ch'] = '人工充值';
                    break;
                default:
                    $v['mode_ch'] = '未知';
                    break;
            }
        }
        return $data;
    }

    /**
     * 关联广告主表
     * @return HasOne
     */
    public function advertiserUser(): HasOne
    {
        return $this->hasOne(AdvertiserUser::class, 'id', 'ad_user_id');
    }

}




